import allure
from selenium.webdriver.common.by import By

from .base import Base
from .product_listing_page import ProductListingPage


class PageJumps(Base):  # 页面跳转
    __MERCHANDISE_CONTROL = (By.XPATH, "//div[@class='sidebar-container el-scrollbar']"
                                       "//ul[@class='el-menu']/div[3]")     # 商品管理
    __ORDERING_LISTING_PAGE = (By.XPATH, "//div[@class='sidebar-container el-scrollbar']"
                                         "//ul[@class='el-menu']/div[3]/li/ul/div[1]")  # 商品列表
    __PRODUCT_LISTING_PAGE = (By.XPATH, "//div[@class='sidebar-container el-scrollbar']"
                                        "//ul[@class='el-menu']/div[3]/li/ul/div[2]")   # 商品上架

    def goto_ordering_listing_page(self):   # 商品列表页
        with allure.step("跳转到商品列表页"):
            self.find_click(self.__MERCHANDISE_CONTROL)
            self.find_click(self.__ORDERING_LISTING_PAGE)
        return PageJumps(self.driver)

    def goto_product_listing_page(self):    # 商品上架页
        with allure.step("跳转到商品上架页"):
            self.find_click(self.__MERCHANDISE_CONTROL)
            self.find_click(self.__PRODUCT_LISTING_PAGE)
        return ProductListingPage(self.driver)

    def go_check(self):    # 去查询
        from .check import Check
        return Check(self.driver)

    def go_paging_switch(self):    # 去分页
        from .paging_siwtch import PagingSwitch
        return PagingSwitch(self.driver)

    def go_next_page(self):
        from .paging_siwtch import PagingSwitch
        return PagingSwitch(self.driver)

    def go_prev_page(self):
        from .paging_siwtch import PagingSwitch
        return PagingSwitch(self.driver)

    def go_search_page(self):
        from .paging_siwtch import PagingSwitch
        return PagingSwitch(self.driver)
